#include <iostream>

// 栈
// 顺序栈
const int StackSize = 10;

class ArrayStack
{
public:
    // 入栈
    void Push(const int &element)
    {
        if (len == StackSize)
        {
            return;
        }
        a[len++] = element;
    }

    // 出栈
    void Pop()
    {
        if (len == 0)
        {
            return;
        }
        len--;
    }

    // 取栈顶元素
    int *GetTop()
    {
        if (len == 0)
        {
            return;
        }
        return &a[len - 1];
    }

    // 遍历栈元素
    void show()
    {
        while (!)
        {
            std::cout << *GetTop() << " ";
            Pop();
        }
    }

private:
    int a[StackSize];
    int len; // 栈顶指针
};

int main()
{
    // 进制转换器
    ArrayStack s;
    int Num;
    int n;
    std::cin >> Num >> n;
    while (num != 0)
    {
        s.Push(num % n);
        num /= n;
    }
    while (Is)
    {
        if (*s.GetTop() > 9)
        {
            std::cout << *s.GetTop() - 10 + 'a';
        }
        else
        {
            std::cout << *s.GetTop();
        }
        s.Pop();
    }
}

// 链式栈
class LinkStack
{
public:
    LinkStack();
    ~LinkStack();
    void Push()
    {
    }

private:
    DoubleLinkList list;
};

// 队列
// 顺序队列
class ArrayQueue
{
public:
    void Push()
    {
        if ((rear + 1) % size == front) // 判满
        {
            return;
        }
        a[rear++] = element;
        rear % = size;
    }
    void Pop()
    {
        if (front == rear) // 判空
        {
            return;
        }
        front++;
        front %= size;
    }
    int *GetTop()
    {
        if (front == rear) // 判空
        {
            return;
        }
        return &a[front];
    }

private:
    int array[size];
    int front;
    int rear;
};

// 链式队列
class LinkQueue
{
public:
    void Push(const ElementType &elemenmt)
    {
        list.InsertTail(element);
    }
    void Pop()
    {
        list.RemoveByIndex(0);
    }
    void GetTop(const ElementType &elemenmt)
    {
        list.FindByIndex(0, elemenmt);
    }
    bool IsEmpty()
    {
        return list.Size() == 0;
    }

private:
    DoubleLinkList list;
};

// 约瑟夫环
int main()
{
    LinkQueue q;
    for (int i = 1; i < 14; i++)
    {
        q.Push(i);
    }
    int count = 0;
    while (q.size > 1)
    {
        long num = (long)*q.GetTop();
        q.Pop();
        count++;
        if (count == 3)
        {
            std::cout << "num被杀死" << std::endl;
        }
        else
        {
            q.Push(num);
        }
    }
    std::cout << *q.GetTop() << "留了下来" << std::endl;
}

size_t paretion(int *a, size_t start, size_t end)
{
    size_t left = start;
    size_t right = end;
    size_t tmp = start;
    while (left < right)
    {
        if (a[right] > a[tmp])
        {
            right--;
        }
    }
}

// 利用栈实现快速排序
void FastSortNoRecur()
{
    s.Push(start);
    s.Push(end);

    while (!s.IsEmpty())
    {
        size_t right = s.GetTop();
        s.pop();
        size_t left = s.GetTop();
        s.Pop();

        size_t mid = partpaition(a, left, right)
        {
            if (mid != 0 && left < mid - 1)
            {
                s.Push(left);
                s.Push(mid - 1);
            }
            if (mid + 1 < right)
            {
                s.Push(mid + 1);
                s.Push(right);
            }
        }
    }
}

// 两个栈实现一个队列
class MyQueue
{
public:
    void Push(const ElementType &element)
    {
        while (s2.IsEmpty() == false)
        {
            s1.Push(s2.*GetTop());
            s2.Pop();
        }
        s1.Push(element);
    }
    void Pop()
    {
        while (s1.IsEmpty() == false)
        {
            s2.Push(s1.*GetTop);
            s1.Pop();
        }
        s2.Pop();
    }
    ElememntType *GetFront()
    {
        while (s1.IsEmpty() == false)
        {
            s2.Push(s1.*GetTop);
            s1.Pop();
        }
        return &s2.GetTop();
    }
    bool IsEmpty()
    {
        return s1.IsE3() && S2KL
    }

private:
    LinkStack s1;
    LinkStack s2;
};

// 两个队列实现一个栈
class MyStack
{
public:
    void Push(const el)
    {
        while (q2.Is == false)
        {
            q1.Push(*q2.GetTop());
            q2.Pop();
        }
        q1.Push(el);
    }

    void Pop()
    {
        while (q1.size() > 1)
        {
            q2.Push(*q1.GetTop());
            q1.Pop();
        }
        q1.Pop();
        while (q2.IsEmpty == false)
        {
            q1.Push(q2.GetTop());
            q2.Pop();
        }
    }

    ElementType *GetTop()
    {
        while (q1.size() > 1)
        {
            q2.Push(*q1.GetTop());
            q1.Pop();
        }
        ElementType *r = q1.GetTop();
        q2.Push(r);
        q1.Pop();
        while (q2.IsEmpty == false)
        {
            q1.Push(q2.GetTop());
            q2.Pop();
        }
        return r;
    }

private:
    LinkQueue q1;
    LinkQueue q2;
};
